package com.example.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.commonsutils.R;
import com.example.eduservice.entity.EduCourse;
import com.example.eduservice.entity.EduTeacher;
import com.example.eduservice.service.EduCourseService;
import com.example.eduservice.service.EduTeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:tjf
 * @Description:
 */
@Tag(name = "前端教师控制器")
@RequestMapping("/eduservice/teacher/front")
@RestController
public class TeacherFrontController {
    @Resource
    private EduTeacherService teacherService;
    @Resource
    private EduCourseService courseService;
    @Operation(description = "分页查询教师列表")
    @GetMapping("/list/{current}/{limit}")
    public R queryTeacherListForLimit(@PathVariable("current") Integer current,
                                      @PathVariable("limit") Integer limit){
        HashMap<String, Object> map = teacherService.queryTeacherListForLimit(new Page<EduTeacher>(current, limit));
        return R.ok().data(map);
    }
    @Operation(description = "根据id，为前端页面提供教师信息--个人信息及所教课程")
    @GetMapping("/teacherFrontInfo/{id}")
    public R queryTeacherFrontInfoById(@PathVariable("id") String id){
        EduTeacher teacherInfo = teacherService.getById(id);

        List<EduCourse> courseList = courseService.queryCourseListByTeacherId(id);

        return R.ok().data("teacher", teacherInfo).data("courseList", courseList);
    }
}
